/*
 * ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Topless JSF.
 *
 * The Initial Developer of the Original Code is
 * Marco Antonio Villalobos, Jr. (mvillalobos@kineteque.com).
 * Portions created by the Initial Developer are Copyright (C) 2010
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Marco Antonio Villalobos, Jr. (mvillalobos@kineteque.com).
 *
 * ***** END LICENSE BLOCK *****
 */

package kineteque.jsf.topless.components.delegate;

import javax.faces.component.UIComponentBase;
import javax.faces.component.UIComponent;
import javax.faces.component.FacesComponent;
import javax.el.ValueExpression;

/**
 * Provides a delegate render that will render the contained delegate.
 */
@FacesComponent(value = "topless.jsf.delegate")
@Deprecated
public class UIDelegateContainer extends UIComponentBase {

    /**
     * <p>Return the identifier of the component family to which this
     * component belongs.  This identifier, in conjunction with the value
     * of the <code>rendererType</code> property, may be used to select
     * the appropriate {@link javax.faces.render.Renderer} for this component instance.</p>
     */
    @Override
    public String getFamily() {
        return "javax.faces.Panel";
    }

    /** The delegate to render. */
    protected UIComponent delegate = null;

    /**
     * When false the delegate and all of its children will be
     * completely rendered, when true only the delegate's chlidren
     * will be rendered.
     */
    protected boolean onlyRenderDelegateChildren = false;

    /**
     * Retrieves the delegate.
     *
     * @return the delegate.
     */
    public UIComponent getDelegate() {
        if (delegate!=null) {
            return delegate;
        }
        ValueExpression ve = getValueExpression("delegate");
        return ve != null ? (UIComponent) ve.getValue(getFacesContext().getELContext()) : null;
    }

    /**
     * Assigns the delegate.
     *
     * @param delegate The delegate.
     */
    public void setDelegate(UIComponent delegate) {
        this.delegate = delegate;
    }

    /**
     * Retrieves the only render delegate children flag.
     *
     * When false the delegate and all of its children will be
     * completely rendered, when true only the delegate's chlidren
     * will be rendered.
     *
     * @return The only render delegate children flag.
     */
    public boolean isOnlyRenderDelegateChildren() {
        return onlyRenderDelegateChildren;
    }

    /**
     * Assigns the only render delegate children flag.
     *
     * When false the delegate and all of its children will be
     * completely rendered, when true only the delegate's chlidren
     * will be rendered.
     *
     * @param onlyRenderDelegateChildren The only render delegate children flag.
     */
    public void setOnlyRenderDelegateChildren(boolean onlyRenderDelegateChildren) {
        this.onlyRenderDelegateChildren = onlyRenderDelegateChildren;
    }

    

}
